package com.ymatou.iapi.livebuyer.testcase;

import java.util.Arrays;
import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.QueryProductVideoGifBean;
import com.ymatou.iapi.livebuyer.service.QueryProductVideoGifCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 获取商品讲解动图Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_QueryProductVideoGif {
	private static QueryProductVideoGifBean queryproductvideogifBean;
	private static QueryProductVideoGifCall queryproductvideogifCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static LiveRoomWapper liveRoomWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商品讲解动图Test");
	}

	@Before
	public void caseUp() {
		queryproductvideogifBean = new QueryProductVideoGifBean();
		queryproductvideogifCall = new QueryProductVideoGifCall();
		liveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryproductvideogifCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductVideoGif_001() {
		Logger.start(true, "获取直播讲解Gif，成功");
		try {
			
			// 创建直播，
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 1秒钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			Date starttime = new Date(now.getTime() + 4000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(livedto.getId(), sellerId, productId);
			Thread.sleep(5000);
			LiveRoomCallService.SellerLiveOnline(livedto.getId(), sellerId);
			// 开始直播录制
			String taskId = LiveRoomCallService.CreateProductVideo(livedto.getId(), sellerId, productId,TestDataManager.getRandomNum((11)));
			Thread.sleep(20000);
			LiveRoomCallService.StopProductVideo(livedto.getId(), productId);
			Thread.sleep(2000);
			queryproductvideogifBean.setProductIds(Arrays.asList(productId));
			queryproductvideogifCall.setData(queryproductvideogifBean);
			queryproductvideogifCall.callService();
			Logger.verifyEquals("200", queryproductvideogifCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
		
		
		
	}
}